package com.qinggeng.framework.config.mq.impl;

import com.alibaba.fastjson.JSON;
import com.qinggeng.common.exception.CustomException;
import com.qinggeng.framework.config.mq.dto.MessageOrdersDTO;
import com.qinggeng.framework.config.mq.handle.MessageHandle;
import com.qinggeng.project.system.service.IPointSaleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class PointSaleRecordHandleImpl implements MessageHandle {
    @Autowired
    private IPointSaleService pointSaleService;
    @Override
    public void handle(String msg) {

       log.info("商品销量统计处理{}"+msg);

        MessageOrdersDTO ordersDTO;
        try{
            ordersDTO= JSON.parseObject(msg,MessageOrdersDTO.class);
            //正式用
            pointSaleService.addPointSale(ordersDTO.getOrdersNo());
            //测试用
            //pointSaleService.testAddPointSale(ordersDTO.getOrdersNo());
        }catch (Exception e){
            log.error("商品销量统计失败{}",e.getMessage());
            throw new CustomException(e.getMessage());
        }
    }
}
